# -*- coding: UTF-8 -*- 
import re
f = open('fx.txt','r')
fp = open('fp.txt','w+')
c = f.readlines()
for x in c:
    if re.findall(r'.*input:\s(\d+)\sbytes/sec.*',x):
        fp.write('输入峰值速率（bytes/sec）：%s bytes/sec\n'%(re.findall(r'.*input:\s(\d+)\sbytes/sec.*',x)[0]))
    if re.findall(r'.*output:\s(\d+)\sbytes/sec.*',x):
        fp.write('输出峰值速率（bytes/sec）：%s bytes/sec\n'%(re.findall(r'.*output:\s(\d+)\sbytes/sec.*',x)[0]))
    if re.findall(r'.*input:\s(\d+)\spackets.*',x):
        fp.write('5分钟平均输入速率(packets/sec,bytes/sec)：%s packets/sec, %s bytes/sec\n'%(re.findall(r'.*input:\s(\d+)\spackets.*',x)[0],re.findall(r'.*sec\s(\d+)\sbytes/sec.*',x)[0]))
    if re.findall(r'.*output:\s(\d+)\spackets.*',x):
        fp.write('5分钟平均输出速率(packets/sec,bytes/sec)：%s packets/sec, %s bytes/sec\n'%(re.findall(r'.*output:\s(\d+)\spackets.*',x)[0],re.findall(r'.*sec\s(\d+)\sbytes/sec.*',x)[0]))
    if re.findall(r'.*input:\s(\d+)\spackets.*',x):
        fp.write('5分钟平均输入带宽利用率：%s\n'%(re.findall(r'.*bytes/sec\s+(\S+)',x)[0]))
    if re.findall(r'.*output:\s(\d+)\spackets.*',x):
        fp.write('5分钟平均输出带宽利用率: %s\n'%(re.findall(r'.*bytes/sec\s+(\S+)',x)[0]))
    if re.findall(r'Input\s.total.',x):
        fp.write('输入总包数：（packets）：%s packets\n'%(re.findall(r'.*Input\s.total.:(\d+)\spackets.*',x)[0]))
    if re.findall(r'Input\s.total.',x):
        fp.write('输入总流量（bytes）：%s bytes\n'%(re.findall(r'.*packets,\s(\d+)\sbytes',x)[0]))
    if re.findall(r'Output\s.total.',x):
        fp.write('输出总包数：（packets）：%s packets\n'%(re.findall(r'.*Output\s.total.:(\d+)\spackets.*',x)[0]))
    if re.findall(r'Output\s.total.',x):
        fp.write('输出总流量（bytes）：%s bytes\n'%(re.findall(r'.*packets,\s(\d+)\sbytes',x)[0]))
f.close()
fp.close()
